package day9.homework;

import java.util.Arrays;
import java.util.Scanner;

import org.junit.Test;

public class Demo {

	@Test
	public void test1() {
		// 写代码时候不要只测试标准情况，也要测试极端情况、边界情况
		// String str = "---java Android---";
		String str = "----";
		System.out.println(trim(str));
	}
	
	public String trim(String str) {
		int startIndex = 0;
		int endIndex = str.length() - 1;
		while (startIndex <= endIndex && str.charAt(startIndex) == '-') {
			startIndex++;
		}
		
		while (startIndex <= endIndex && str.charAt(endIndex) == '-') {
			endIndex--;
		}
		
		return str.substring(startIndex, endIndex + 1);
	}
	
	@Test
	public void test2() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入字符串：");
		String str = scanner.nextLine();
		String result = toUpperCase(str);
		System.out.println(result);
	}

	private String toUpperCase(String str) {
		char[] array = str.toCharArray();
		for (int i = 0; i < array.length; i++) {
			if (array[i] >= 'A' && array[i] <= 'Z') {
				array[i] = (char)(array[i] + 32);
			}
		}
		return new String(array);
	}
	
	
	@Test
	public void test5() {
		// 正则表达式
		String str = "this is my homework! I must finish it!";
		String[] array = str.split(" ");
		System.out.println(array.length);
	}
}
